package com.yash.rms.domain;

import com.yash.rms.util.Constants;
import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;
import flexjson.transformer.DateTransformer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.json.RooJson;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@RooDbManaged(automaticallyDelete = true)
@RooJson
@RooJpaActiveRecord(versionField = "", table = "resource_allocation", finders = { "findResourceAllocationsByEmployeeId" })
public class ResourceAllocation {

    public String toJson() {
        return new JSONSerializer().exclude("*.class").transform(new DateTransformer(Constants.DATE_PATTERN), Date.class).serialize(this);
    }

    public static com.yash.rms.domain.ResourceAllocation fromJsonToResourceAllocation(String json) {
        return new JSONDeserializer<ResourceAllocation>().use(null, ResourceAllocation.class).use(Date.class, new DateTransformer(Constants.DATE_PATTERN)).deserialize(json);
    }

    public static String toJsonArray(Collection<com.yash.rms.domain.ResourceAllocation> collection) {
        return new JSONSerializer().exclude("*.class").transform(new DateTransformer(Constants.DATE_PATTERN), Date.class).serialize(collection);
    }

    public static Collection<com.yash.rms.domain.ResourceAllocation> fromJsonArrayToResourceAllocations(String json) {
        return new JSONDeserializer<List<ResourceAllocation>>().use(null, ArrayList.class).use("values", ResourceAllocation.class).use(Date.class, new DateTransformer(Constants.DATE_PATTERN)).deserialize(json);
    }
}
